package com.ljsw.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.ljsw.activity.R;
/**
* @Package com.ljsw.dialog 
* @Description: TODO(用户验证框) 
* @author 郑鸿博   
* @date 2015-12-8 上午10:36:12 
* @version V1.0
 */
public class UserLoginDialog {
	public UserLoginDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();//获取屏幕分辨率
	}
	private Context context;
	private Display display;
	private Dialog dialog;
	private LinearLayout lLayout_load;
	private TextView title;
	private EditText name,pwd;
	private Button queding,quxiao;
	private Handler mHandler;
	
	public void setmHandler(Handler mHandler) {
		this.mHandler = mHandler;
	}

	public UserLoginDialog builder(){
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_check_user, null);
		lLayout_load = (LinearLayout) view.findViewById(R.id.layout_check_user);
		name = (EditText) view.findViewById(R.id.name_check);
		title = (TextView) view.findViewById(R.id.usertishi);
		pwd = (EditText) view.findViewById(R.id.pwd_check);
		queding = (Button) view.findViewById(R.id.system_login_btn);
		quxiao = (Button) view.findViewById(R.id.system_login_cancel);
		// 添加Dialog样式
		dialog = new Dialog(context, R.style.UserLoginDialog);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域不关闭Dialog	
		// 调整dialog背景大小
		lLayout_load.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		queding.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				Message message=new Message();
				Bundle bundle=new Bundle();  
                bundle.putString("name",name.getText().toString()); 
                bundle.putString("pwd",pwd.getText().toString()); 
                message.setData(bundle);//bundle传值，耗时，效率低  
                mHandler.sendMessage(message);//发送message信息  
                message.what=10;//标志是哪个线程传数据 
				dialog.dismiss();
			}
		});
		quxiao.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				dialog.dismiss();
			}
		});
		return this;
	}
	
	/**
	 * 设置标题
	 * @param title
	 * @return
	 */
	public UserLoginDialog setTitle(String msg){
		title.setTextColor(Color.RED);
		title.setText(msg);
		return this;
	}
	
	public void show() {
		dialog.show();
	}
	public void dismiss(){
		dialog.dismiss();
	}
	public boolean isShow(){
		return dialog.isShowing();
	}
	
	public void clear(){
		name.setText("");
		pwd.setText("");
	}
}
